﻿#include "login.h"
#include "ui_login.h"
#include"qpainter.h"
#include "functionselect.h"
#include "dialog/myhelper.h"
#include "DataBase/dboperation.h"
#include "DataBase/dbhelper.h"
#include "DataBase/mysql.h"
#include "constant.h"
Login::Login(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Login)
{
    ui->setupUi(this);
    checkSystem();
//    this->showFullScreen();
    //初始化所有账号为未登录状态，因为服务端只要重启，客户端所有用户失去连接，需要重新登录
    QString file=Constant::DataBasePath;
    Qt::HANDLE threadId = QThread::currentThreadId();
    QString threadIdStr = QString::number(reinterpret_cast<quintptr>(threadId));

    MySql *mySql = new MySql(file,threadIdStr);
    mySql->MyUpdateLoginState_All();
    delete mySql;
//    MySql::getInstance(file)->MyUpdateLoginState_All();
    if(Constant::ShowFullScreen)
        this->showFullScreen();
//    ui->label_login_logo->setText("nih");
}

Login::~Login()
{
    delete ui;
}

void Login::checkSystem(){
//    QString dabaPosition=QCoreApplication::applicationDirPath()+"/DataBase/Data.db";//数据库文件,和exe同目录
//    if(!dBOperation.CheckDataBase(dabaPosition)){
//        myHelper::ShowMessageBoxError("数据库发生错误!");
//    }
//    dBOperation.closedatabase();
    QDir dir(Constant::DataBasePath);
    if(!dir.exists())
        dir.mkpath(Constant::DataBasePath);

}
void Login::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.drawPixmap(rect(),QPixmap(":/images/share/selectmodel_page_bg2.png"),QRect());
}


void Login::on_login_pushButton_login_clicked()
{
    FunctionSelect *functionsel=new FunctionSelect;
    functionsel->show();
    this->close();


}


void Login::on_login_exit_bt_clicked()
{
    this->close();
}

